package com.lagou.servlet;

import com.lagou.model.Student;
import com.lagou.service.UserService;
import com.lagou.service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


@WebServlet(name = "findStudentServlet",urlPatterns = "/findStudentServlet")
public class findStudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer id = Integer.parseInt(request.getParameter("code"));
        UserService su = new UserServiceImpl();
        Student studentById = su.findStudentById(id);
        System.out.println(studentById);
        List<Student> students = new ArrayList<>();
        students.add(studentById);
        if(studentById!=null){
            request.setAttribute("allStudent",students);
            // response.sendRedirect("findOneStudent.jsp");
            request.getRequestDispatcher("findOneStudent.jsp").forward(request, response);
        }else{
            System.out.println("错误!--------------------------------------------------------");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
